import java.util.ArrayList;

public class RegexGraph {
	

	public static char[] fullRange = new char[128];
	
	static {
		for (int i = 0; i < fullRange.length; i++){
			fullRange[i] = (char)i;
		}
	}
	
	
	public char[] range;
	
	public RegexGraph(char[] range){
		this(range, false);
	}
	
	public RegexGraph(char[] range, boolean negated){
		if (!negated){
			this.range = range;
		}
		else{
			int[] temp = new int[fullRange.length];
			for (int i = 0; i < temp.length; i++){
				temp[i] = i;
			}
			for (int i = 0; i < range.length; i++){
				temp[(int)range[i]] = -1;
			}
			ArrayList<Character> toAdd = new ArrayList<Character>(256);
			for (int i = 0; i < temp.length; i++){
				if (temp[i] != -1){
					toAdd.add((Character)((char)temp[i]));
				}
			}
			this.range = new char[toAdd.size()];
			for (int i = 0; i < toAdd.size(); i++){
				this.range[i] = toAdd.get(i);
			}
		}
	}
	
	public static char[] rangeOr(char[] range1, char[] range2){
		char[] ret = new char[range1.length + range2.length];
		for (int i = 0; i < range1.length; i++){
			ret[i] = range1[i];
		}
		for (int i = 0; i < range2.length; i++){
			ret[i+range1.length] = range2[i];
		}
		return ret;
	}
	
	public static char[] makeRange(char start, char end){
		if (end < start) return new char[0];
		
		char[] ret = new char[end-start];
		for (char c = start; c < end; c++){
			ret[(int)(c - start)] = c;
		}
		return ret;
	}
	

	public RegexGraph concatenate(RegexGraph rg1, RegexGraph rg2){
		return null;
	}
	
	public RegexGraph union(RegexGraph rg1, RegexGraph rg2){
		return null;
	}
	
	public RegexGraph star(RegexGraph rg){
		return null;
	}
	
	public RegexGraph plus(RegexGraph rg){
		return null;
	}
	
	
	public static void main(String[] args){
		
		//Make an RG for [a-zA-Z]
		char[] tryme = makeRange('A', 'Z');
		char[] tryme2 = makeRange('a', 'z');
		RegexGraph rg = new RegexGraph(tryme, false);
		
		for (int i = 0; i < rg.range.length; i++){
			System.out.print(rg.range[i] + " ");
		}
		
		char[] tryNow = rangeOr(tryme, tryme2);
		RegexGraph rg2 = new RegexGraph(tryNow);
		System.out.println();
		for (int i = 0; i < rg2.range.length; i++){
			System.out.print(rg2.range[i] + " ");
		}
		
		//Make an RG for [^a-zA-Z]
		char[] useThis = rangeOr(makeRange('A', 'Z'), makeRange('a', 'z'));
		RegexGraph nonLetter = new RegexGraph(useThis, true);
		System.out.println();
		for (int i = 0; i < nonLetter.range.length; i++){
			System.out.print(nonLetter.range[i] + " ");
		}
	}
	
	
}
